
// 引入公共样式
require('../css/commCss/normalize.css')

// 引入重置补充样式
require('../css/commCss/reset.css')

// 引入公共样式
require('../css/commCss/property.css')

// 引入公共模块
require('../css/commCss/basic.css')

// 字体图标
require('../fonts/iconfont.css')

require('../libs/swiper/css/swiper.css')


// 引入weui
require('weui')
const weui = require('weui.js')

// 引入当前样式
require('../css/home.less')

// 引入axios
const axios = require('axios')

import Swiper, { Autoplay, Pagination } from 'swiper'

  Swiper.use([Autoplay, Pagination]);
var mySwiper = new Swiper('.swiper', { 
      autoplay:{
        disableOnInteraction: false
      },
      loop : true,
      pagination: {
          el: '.swiper-pagination',
          clickable :true,
        },
});

// 获取元素
const rank = document.querySelector('#rank')
const punchDay = document.querySelector('#punchDay')
const todayPunch = document.querySelector('#todayPunch')
const badge = document.querySelector('#badge')


// 数据渲染
axios.get('http://139.9.177.51:8099/headPageInfo', {
    params: {
      userId: localStorage.getItem('userId')
    }
  }).then(function (res) {

    if (res.data.status === 0) {
      rank.textContent = res.data.data.rank
      punchDay.textContent = `累计打卡${res.data.data.punchIn}天`
      badge.textContent = `${res.data.data.insigniaNum}`

      //rank.textContent = res.data.data.rank
      res.data.data.isPunch === 'true' ? todayPunch.textContent = '已打卡' : todayPunch.textContent = '今日打卡'
    }
  })



   /**
   * 3.今日打卡
   */
    todayPunch.addEventListener('click', function () {
      axios.get('http://139.9.177.51:8099/clockIn', {
        params: {
          userId: localStorage.getItem('userId')
        }
      }).then(function (res) {
        if (res.data.status === 0) {
          punchDay.textContent = `累计打卡${res.data.data.punchIn++}天`
          todayPunch.textContent = '已打卡'
          weui.toast('打卡成功', 1000)
        } else {
          weui.toast('已打卡', 1000)
        };
      })
    })